﻿#pragma once
#include <algorithm4cpp/pinyin_util.h>
using namespace algorithm4cpp;

class pinyin_util_test :
	public Test
{
public:
	pinyin_util_test(void);
	~pinyin_util_test(void);

protected:
	virtual void SetUp()
	{
	}

	virtual void TearDown()
	{
	}

	void test_is_chinese()
	{
		wstring chinese = L"一二三四五六七八九十上中下人口手刀弓车舟很多汉字";
		wstring non_chinese = L"qwertyuiop[]\\　";

		for ( size_t index = 0; index < chinese.length(); ++index ) {
			EXPECT_TRUE( pinyin_util::is_chinese( chinese[index] ) );
		}

		for ( size_t index = 0; index < non_chinese.length(); ++index ) {
			EXPECT_FALSE( pinyin_util::is_chinese( non_chinese[index] ) );
		}
	}

	void test_char_to_pinyin()
	{
		map<wchar_t, wstring> x;
		x[L'一'] = L"yi";
		x[L'二'] = L"er";
		x[L'中'] = L"zhong";
		x[L'喊'] = L"han";
		x[L'昵'] = L"ni";

		for ( map<wchar_t, wstring>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_pinyin( it->first, it->second );
		}
	}

	void test_char_to_shengmu()
	{
		map<wchar_t, wchar_t> x;
		x[L'一'] = L'y';
		x[L'二'] = L'e';
		x[L'中'] = L'z';
		x[L'喊'] = L'h';

		for ( map<wchar_t, wchar_t>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_shengmu( it->first, it->second );
		}
	}

	void one_to_pinyin() 
	{
		map<wstring, wstring> x;
		x[L"一"] = L"yi";
		x[L"二"] = L"er";
		x[L"中"] = L"zhong";
		x[L"喊"] = L"han";

		for ( map<wstring, wstring>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_pinyin( it->first, it->second );
		}
	}

	void some_to_pinyin()
	{
		map<wstring, wstring> x;
		x[L"汉字"] = L"hanzi";
		x[L"广州"] = L"guangzhou";
		x[L"内地上周甲型流感死亡"] = L"neidishangzhoujiaxingliugansiwang";

		for ( map<wstring, wstring>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_pinyin( it->first, it->second );
		}
	}

	void mix_to_pinyin()
	{
		map<wstring, wstring> x;
		x[L"内地上周甲型流感死亡91人"] = L"neidishangzhoujiaxingliugansiwang91ren";
		x[L"孕妇所占比例提高】卫"] = L"yunfusuozhanbilitigao】wei";
		x[L"上周(12月14日-20日)，中国境内31个省份报告"] = L"shangzhou(12yue14ri-20ri)，zhongguojingnei31geshengfenbaogao";
		x[L"明显增高。http://sinaurl.cn/hXALo"] = L"mingxianzenggao。http://sinaurl.cn/hXALo";
		x[L"又是一个137昵称nick"] = L"youshiyige137nichengnick";

		for ( map<wstring, wstring>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_pinyin( it->first, it->second );
		}
	}

	void non_to_pinyin()
	{
		vector<wstring> x;
		x.push_back( L"2010" );
		x.push_back( L"csbeyond：@" );
		x.push_back( L"http://sinaurl.cn/hXZ" );
		x.push_back( L"All work and no play makes jack a dull boy." );

		for ( size_t index = 0; index < x.size(); ++index ) {
			test_to_pinyin( x[index], x[index] );
		}
	}

	void one_to_shengmu()
	{
		map<wstring, wstring> x;
		x[L"一"] = L"y";
		x[L"二"] = L"e";
		x[L"中"] = L"z";
		x[L"喊"] = L"h";

		for ( map<wstring, wstring>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_shengmu( it->first, it->second );
		}
	}
	void some_to_shengmu()
	{
		map<wstring, wstring> x;
		x[L"汉字"] = L"hz";
		x[L"广州"] = L"gz";
		x[L"内地上周甲型流感死亡"] = L"ndszjxlgsw";

		for ( map<wstring, wstring>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_shengmu( it->first, it->second );
		}
	}
	void mix_to_shengmu()
	{
		map<wstring, wstring> x;
		x[L"内地上周甲型流感死亡91人"] = L"ndszjxlgsw91r";
		x[L"孕妇所占比例提高】卫"] = L"yfszbltg】w";
		x[L"上周(12月14日-20日)，中国境内31个省份报告"] = L"sz(12y14r-20r)，zgjn31gsfbg";
		x[L"明显增高。http://sinaurl.cn/hXALo"] = L"mxzg。http://sinaurl.cn/hXALo";
		x[L"又是一个137昵称nick"] = L"ysyg137ncnick";

		for ( map<wstring, wstring>::const_iterator it = x.begin(); it != x.end(); ++it ) {
			test_to_shengmu( it->first, it->second );
		}
	}

	void non_to_shengmu()
	{
		vector<wstring> x;
		x.push_back( L"2010" );
		x.push_back( L"csbeyond：@" );
		x.push_back( L"http://sinaurl.cn/hXZ" );
		x.push_back( L"All work and no play makes jack a dull boy." );

		for ( size_t index = 0; index < x.size(); ++index ) {
			test_to_shengmu( x[index], x[index] );
		}
	}

private:
	template<typename T>
	void test_to_pinyin( const T & source, const wstring & expected )
	{
		set<wstring> result = pinyin_util::chinese_to_pinyin( source );
		EXPECT_TRUE( result.find( expected ) != result.end() );
	}

	template<typename T>
	void test_to_shengmu( const T & source, const T & expected )
	{
		set<T> result = pinyin_util::chinese_to_shengmu( source );
		EXPECT_TRUE( result.find( expected ) != result.end() );
	}
};
